<?php
session_start();
include_once "checkLogin.php";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="css/menu.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="js/nav.js" type="text/javascript"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="js/TweenMax.min.js"></script>
    <link href="css/word.css" rel="stylesheet" type="text/css"/>
    <title>添加读者信息</title>
    <style>
        .layui-form{
            width: 50%;
            margin:3% auto;
        }
        #c{
            height: 650px;
        }
        #now{
            margin-left: 5%;
            margin-top: 1%;
        }
        #main{
            height: 900px;
        }
    </style>
</head>
<body>
<canvas id="Mycanvas" style="position: absolute;left: 0%;width: 100%;height: 99%"></canvas>
<div id="main">
    <header>
        <div id="header1">
            <div id="a"></div>
            <img src="img/logo1.png">
            <h2 class="letter-wrap"  data-stagger="-0.015">清华大学图书馆管理系统</h2>
            <span>当前登录用户：<?php echo $_SESSION['admin']?></span>
        </div>
    </header>
    <div class="navmain">
        <div id="time"><span></span></div>
        <ul id="nav_all">
            <li><a href="index.php">首页</a></li>
            <?php
            include_once "conn.php";
            $main = new main();
            $info = $main->checkAdmin($_SESSION['admin']);
            if ($info['system']){
                ?>
                <li><a href="#">系统设置</a>
                    <ul style="display: none;">
                        <li><a href="library.php">图书馆信息</a></li>
                        <li><a href="admin.php">管理员设置</a></li>
                        <li><a href="#">参数设置</a></li>
                        <li><a href="shujia.php">书架设置</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info['readerset']){
                ?>
                <li><a href="#">读者管理</a>
                    <ul style="display: none;">
                        <li><a href="readertype.php">读者类型管理</a></li>
                        <li><a href="user.php">读者档案管理</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info['bookset']){
                ?>
                <li><a href="tushudangan.php">图书档案管理</a></li>
                <?php
            }
            if ($info['book']){
                ?>
                <li><a>图书借还</a>
                    <ul style="display: none;">
                        <li><a href="bookjieyue.php">图书借阅</a></li>
                        <li><a href="bookxujie.php">图书续借</a></li>
                        <li><a href="bookback.php">图书归还</a></li>
                    </ul>
                </li>
                <?php
            }
            if ($info['syschaxun']){
                ?>
                <li> <a>系统查询</a>
                    <ul style="display: none;">
                        <li><a href="tushudanganchaxun.php">图书档案查询</a></li>
                        <li><a href="jieyuechaxun.php">图书借阅查询</a></li>
                        <li><a href="jieyue.php">借阅到期提醒</a></li>
                    </ul>
                </li>
                <?php
            }
            ?>
            <li>
                <a href="pw.php">更改口令</a>
            </li>
            <li><a href="zhuxiao.php">注销</a> </li>
        </ul>
    </div>
    <div id="b"></div>
    <div id="c">
        <div id="now">当前位置：读者管理 > 读者档案管理 > 添加读者信息 >>></div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">单选框</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男" checked>
                    <input type="radio" name="sex" value="女" title="女">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">条形码</label>
                <div class="layui-input-block">
                    <input type="number" name="barcode" id="tip" required lay-verify="required" placeholder="请输入条形码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">读者类型</label>
                <div class="layui-input-inline">
                    <select name="readertype" lay-verify="required">
                        <?php
                        include_once "conn.php";
                        $main = new main();
                        $result= $main->readertype();
                        print_r($result);
                        for ($i = 0; $i < count($result); $i++) {
                            ?>
                            <option value="<?php echo $result[$i]['number']?>"><?php echo $result[$i]['name']?></option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">职业</label>
                <div class="layui-input-inline">
                    <input type="text" name="work" required lay-verify="required" placeholder="请输入职业" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">出生日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="chusheng" required lay-verify="required" class="layui-input" id="test19" autocomplete="off" placeholder="yyyy-MM-dd">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">有效证件</label>
                <div class="layui-input-inline">
                    <select name="zhenjian" lay-verify="required">
                        <option value="学生证">学生证</option>
                        <option value="身份证">身份证</option>
                        <option value="军官证">军官证</option>
                        <option value="教师证">教师证</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-block">
                    <input type="number" name="number" required lay-verify="required" placeholder="请输入证件号码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-inline">
                    <input type="number" name="phone" required lay-verify="phone" placeholder="请输入电话号码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">E-mail</label>
                <div class="layui-input-inline">
                    <input type="email" name="mail" required lay-verify="email" placeholder="请输入邮箱" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="history.back();">返回</button>
                </div>
            </div>
        </form>
    </div>
    <footer>
        <hr id="one">
        <hr id="two">
        CopyRight © 2019 www.cdp.cn.com 清华大学图书馆
    </footer>
</div>
</body>
<script src="layui/layui.js"></script>
<script src="js/logo.js"></script>
<script src="js/bg.js"></script>
<script>
    //Demo
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            laydate = layui.laydate;
        laydate.render({
            elem: '#test19'
            ,value: '1989-10-14'
            ,isInitValue: true
        });
        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log(data.field);//当前容器的全部表单字段，名值对形式：{name: value}
            $.ajax({
                type: "POST",
                url: "add1user.php",
                data: {
                    name: data.field.name,
                    sex: data.field.sex,
                    barcode: data.field.barcode,
                    readertype: data.field.readertype,
                    chusheng: data.field.chusheng,
                    work: data.field.work,
                    zhenjian: data.field.zhenjian,
                    number: data.field.number,
                    phone: data.field.phone,
                    mail: data.field.mail,
                },
                dataType: 'JSON',
                cache: false, //不缓存此页面
                success: function (data) {
                    if (data.error === 1) {
                        layer.msg('添加成功!');
                        setTimeout(function () {
                            window.location.href=document.referrer;
                        },500)
                    }else if (data.error === 2){
                        layer.tips('条形码已经存在了!请重试', '#tip', {
                            tips: [1, '#FF0000'],
                            time: 4000
                        });
                    }
                    else {
                        layer.msg('添加失败!请重试!');
                    }
                }
            });
            return false;
        });
    });

</script>
</html>
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/8
 * Time: 11:21
 */